﻿using UnityEngine;

public class BodyData {
	// === Public =====================================================================================================
	public Vector3 Direction { get; private set; }
	public Vector3 NextDirection { get; private set; }
	public Vector3 CurPoint { get; private set; }
	public Vector3 NextPoint { get; private set; }
	public bool IsPause { get; private set; }
	public BodyData Target { get; private set; }

	public BodyData(Vector3 curPoint, Vector3 direction) {
		IsPause = false;
		Direction = NextDirection = direction;
		CurPoint = curPoint;
		NextPoint = curPoint + NextDirection;
		Target = null;
	}

	public BodyData(BodyData targetData) {
		IsPause = true;
		Direction = targetData.Direction;
		NextDirection = targetData.NextDirection;
		CurPoint = targetData.CurPoint;
		NextPoint = targetData.NextPoint;
		Target = targetData;
	}

	public bool HasTarget() {
		return Target != null;
	}

	public void UpdatePointAndDirection() {
		CurPoint = NextPoint;
		NextPoint += NextDirection;
		Direction = NextDirection;
		if (HasTarget()) {
			NextDirection = Target.Direction;
		}
	}

	public void StartMove() {
		IsPause = false;
	}

	public bool IsVecticalMoving() {
		return Direction == Vector3.forward || Direction == Vector3.back;
	}

	// For the head
	public void SetNextDirection(Vector3 direction) {
		NextDirection = direction;
	}
}
